﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Xml.Linq;
using System.Xml;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

public partial class Search : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        word.Text = "<b>(" + this.Request["s"] + ")</b>";
        SearchResult(this.Request["s"]);
    }


    private void SearchResult(string keyword)
    {
        Label lbl;
        int i = 0;
        string mapLoc = HttpContext.Current.Request.MapPath("~/Content/index.xml");
        XElement m = XElement.Load(mapLoc);
        IEnumerable<XElement> items = from el in m.Elements("index")
                               where (((string)el.Attribute("desc")).ToUpper().Contains(keyword.ToUpper()) || ((string)el.Attribute("word")).ToUpper().Contains(keyword.ToUpper()))
                        select el;
        foreach (XElement el in items)
        {
            i++;
            lbl = new Label();
            lbl.Text = "<p class=texte>" + i + " - <a href='http://cpge.info/" + el.Attribute("url").Value + "'>http://cpge.info/" + el.Attribute("url").Value + "</a><br>" + el.Attribute("desc").Value + "</p>";
            result.Controls.Add(lbl);
        }
        
    }
}